var $table;  
var selectionIds = [];  //保存选中ids  
var sysParameterField = dataObject.sysParameterField;
$(function () {
	  var columns =[
					{field: 'state', checkbox: true},
					{field: 'paramName' , title: sysParameterField.paramName,sortName:'PARAM_NAME' , sortable: true,halign: 'center',align: 'center'},
					//{field: 'paramKey' , title: sysParameterField.paramKey, sortName:'PARAM_KEY' , sortable: true,halign: 'center',align: 'center'},
					{field: 'paramValue' , title: sysParameterField.paramValue, sortName:'PARAM_VALUE' , sortable: true,halign: 'center',align: 'center'},
					//{field: 'regularExp' , title: sysParameterField.regularExp, sortName:'REGULAR_EXP' , sortable: true,halign: 'center',align: 'center'},
					{field: 'describe' , title: sysParameterField.describe, sortName:'DESCRIBE' , sortable: true,halign: 'center',align: 'center'},
					//{field: 'status' , title: sysParameterField.status,formatter: 'statusFormatter' ,sortName:'STATUS' , sortable: true,halign: 'center',align: 'center'},
					//{field: 'cerateBy' , title: sysParameterField.cerateBy, sortName:'CERATE_BY' , sortable: true,halign: 'center',align: 'center'},
					{field: 'createTime' , title: sysParameterField.createTime, sortName:'CREATE_TIME' , sortable: true,halign: 'center',align: 'center'},
					//{field: 'updateBy' , title: sysParameterField.updateBy, sortName:'UPDATE_BY' , sortable: true,halign: 'center',align: 'center'},
					{field: 'updateTime' , title: sysParameterField.updateTime, sortName:'UPDATE_TIME' , sortable: true,halign: 'center',align: 'center'},
			    	{field: 'action', title: pageData.action, formatter: 'actionFormatter', events: 'actionEvents', clickToSelect: false, width: 150, halign: 'center', align: 'center'}
		         ];
    $table = new BSTable("table", '/sys/sysparameter/list', columns,"toolbar",560,'id','ID','sysparameter');
    var queryParams = function(params) {            
         return {
         	  page: params.pageNumber,
         	  limit: params.pageSize,
         	  sidx: params.sortName,
              order: params.sortOrder,
              paramName: vm.search.paramName,
              status: vm.search.status
              //查询字段
             };
     };
	$table.setQueryParams(queryParams);
    $table.init();
});

var actionFormatter = function(value, row, index) {
    var button = [];
	button.push('<a class="edit ml10" href="javascript:void(0)"  data-toggle="tooltip" title="Edit"><i class="glyphicon glyphicon-edit"></i></a>&nbsp;&nbsp;');
	button.push('<a class="detail ml10" href="javascript:void(0)"  data-toggle="tooltip" title="detail"><i class="glyphicon glyphicon-book"></i></a>&nbsp;&nbsp;');	
	return button.join('');
};

var vm = new Vue({
	el:'#app',
	data:{
		showList: true,
		title: null,
		sysParameter: {			
		},
		search:{
			id:null
		}
	},
	methods: {
		query: function () {
			defaultActions.query();
		},
		add: function(){
		    vm.sysParameter={};
			defaultActions.add(vm);
		},
		update: function (event, id) {
		    defaultActions.update(id, $("#table"),$path+"/sys/sysparameter/info/", vm, function(r){
	        	vm["sysParameter"] = r["sysParameter"];
	        });
		},
		saveOrUpdate: function (event) {
		    $('#defaultForm').bootstrapValidator('validate');
			if($('#defaultForm').data('bootstrapValidator').isValid()){
				if(vm.sysParameter.paramName==="WX_EXPIRE_SECONDS"){
					if(vm.sysParameter.paramValue<60||vm.sysParameter.paramValue>2592000){
					alert("微信临时二维码时间必须在60到2592000之间");
					return;
					}
				}
				 var url = vm.sysParameter.id == null || vm.sysParameter.id == ''? ($path+"/sys/sysparameter/save") : ($path+"/sys/sysparameter/update");
				 defaultActions.saveOrUpdate(url ,vm, $("#defaultForm"),"sysParameter",event);
			}
		},
		del: function (event, id) {
		    defaultActions.del(id, $path+"/sys/sysparameter/delete", $("#table") ) ;
		},
		audit:function(status){
			defaultActions.audit(status , $path+"/sys/sysparameter/audit?status="+status, vm);
		},
		reload: function (event) {
		    defaultActions.reload($("#table"),$("#defaultForm"),vm,"sysParameter"); 
		},
		detail: function (event, id) {
			defaultActions.detail(vm, id, event);
		}
	}
});

/*表单校验 start*/
$('#defaultForm').bootstrapValidator({
    feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
	    			    				
	    	paramName: {
	            message: 'The 参数名称 is not valid',
	            validators: {
	                notEmpty: {
	                    message: sysParameterField.paramName+'不能为空！'
	                }
	            }
	        },
	    	    				
	    	paramKey: {
	            message: 'The 参数key is not valid',
	            validators: {
	                notEmpty: {
	                    message: sysParameterField.paramKey+'不能为空！'
	                }
	            }
	        },
	    	    				
	    	paramValue: {
	            message: 'The 参数值 is not valid',
	            validators: {
	                notEmpty: {
	                    message: sysParameterField.paramValue+'不能为空！'
	                },
	                stringLength:{
	            		min:1,
	            		max:200,
	            		message:sysParameterField.paramValue+pageData.overLength + 200
	            	}
	            }
	        },
	    	    				
	    	regularExp: {
	            message: 'The 正则表达式 is not valid',
	            validators: {
	                notEmpty: {
	                    message: sysParameterField.regularExp+'不能为空！'
	                }
	            }
	        },
	    	    				
	    	describe: {
	            message: 'The 参数描述 is not valid',
	            validators: {
	                notEmpty: {
	                    message: sysParameterField.describe+'不能为空！'
	                },
                    stringLength:{
                        min:1,
                        max:255,
                        message:sysParameterField.paramValue+pageData.overLength + 255
                    }
	            }
	        },
	    	    				
	    	status: {
	            message: 'The 系统参数状态：0 启用,1 禁用 is not valid',
	            validators: {
	                notEmpty: {
	                    message: sysParameterField.status+'不能为空！'
	                }
	            }
	        },
	    	    				
	    	cerateBy: {
	            message: 'The 创建人 is not valid',
	            validators: {
	                notEmpty: {
	                    message: sysParameterField.cerateBy+'不能为空！'
	                }
	            }
	        },
	    	    				
	    	createTime: {
	            message: 'The 创建时间 is not valid',
	            validators: {
	                notEmpty: {
	                    message: sysParameterField.createTime+'不能为空！'
	                }
	            }
	        },
	    	    				
	    	updateBy: {
	            message: 'The 更新人 is not valid',
	            validators: {
	                notEmpty: {
	                    message: sysParameterField.updateBy+'不能为空！'
	                }
	            }
	        },
	    	    				
	    	updateTime: {
	            message: 'The 更新时间 is not valid',
	            validators: {
	                notEmpty: {
	                    message: sysParameterField.updateTime+'不能为空！'
	                }
	            }
	        },
	    	    		    
    }
});
/*表单校验 end*/
